package com.ruoyi.bnt.controller;

import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bnt.domain.BntSundayworship;
import com.ruoyi.bnt.service.IBntSundayworshipService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主日敬拜Controller
 * 
 * @author yyj
 * @date 2020-09-21
 */
@Controller
@RequestMapping("/bnt/sundayworship")
public class BntSundayworshipController extends BaseController
{
    private String prefix = "bnt/sundayworship";

    @Autowired
    private IBntSundayworshipService bntSundayworshipService;

    @RequiresPermissions("bnt:sundayworship:view")
    @GetMapping()
    public String sundayworship()
    {
        return prefix + "/sundayworship";
    }

    /**
     * 查询主日敬拜列表
     */
    @RequiresPermissions("bnt:sundayworship:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BntSundayworship bntSundayworship)
    {
        startPage();
        List<BntSundayworship> list = bntSundayworshipService.selectBntSundayworshipList(bntSundayworship);
        return getDataTable(list);
    }

    /**
     * 导出主日敬拜列表
     */
    @RequiresPermissions("bnt:sundayworship:export")
    @Log(title = "主日敬拜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BntSundayworship bntSundayworship)
    {
        List<BntSundayworship> list = bntSundayworshipService.selectBntSundayworshipList(bntSundayworship);
        ExcelUtil<BntSundayworship> util = new ExcelUtil<BntSundayworship>(BntSundayworship.class);
        return util.exportExcel(list, "sundayworship");
    }

    /**
     * 新增主日敬拜
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存主日敬拜
     */
    @RequiresPermissions("bnt:sundayworship:add")
    @Log(title = "主日敬拜", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BntSundayworship bntSundayworship)
    {
        if(bntSundayworship.getId() == null || bntSundayworship.getId().isEmpty())
            bntSundayworship.setId(UUID.randomUUID().toString());
        return toAjax(bntSundayworshipService.insertBntSundayworship(bntSundayworship));
    }

    /**
     * 修改主日敬拜
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BntSundayworship bntSundayworship = bntSundayworshipService.selectBntSundayworshipById(id);
        mmap.put("bntSundayworship", bntSundayworship);
        return prefix + "/edit";
    }

    /**
     * 修改保存主日敬拜
     */
    @RequiresPermissions("bnt:sundayworship:edit")
    @Log(title = "主日敬拜", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BntSundayworship bntSundayworship)
    {
        return toAjax(bntSundayworshipService.updateBntSundayworship(bntSundayworship));
    }

    /**
     * 删除主日敬拜
     */
    @RequiresPermissions("bnt:sundayworship:remove")
    @Log(title = "主日敬拜", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bntSundayworshipService.deleteBntSundayworshipByIds(ids));
    }


    /**
     * 添加序乐
     * @param worshipId
     * @param mmap
     * @return
     */
    @RequiresPermissions("bnt:worshipinfo:add")
    @GetMapping("/worshipinfoXy/{worshipId}")
    public String worshipinfoXy(@PathVariable("worshipId") String worshipId, ModelMap mmap)
    {
        mmap.put("parentId", worshipId);
        mmap.put("infoType", "1");
        return "bnt/sundayworship/worshipinfo/worshipinfo";
    }
    /**
     * 添加回应
     * @param worshipId
     * @param mmap
     * @return
     */
    @RequiresPermissions("bnt:worshipinfo:add")
    @GetMapping("/worshipinfoHy/{worshipId}")
    public String worshipinfoHy(@PathVariable("worshipId") String worshipId, ModelMap mmap)
    {
        mmap.put("parentId", worshipId);
        mmap.put("infoType", "2");
        return "bnt/sundayworship/worshipinfo/worshipinfo";
    }
}
